package com.example.mybank.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybank.entity.Account;
import com.example.mybank.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountService {

    @Autowired
    AccountMapper accountMapper;

    public Account createBankAccount(Account account){
        account.setPassword("bank");
        account.setIs_bank(Boolean.TRUE);
        accountMapper.insert(account);
        return account;
    }

    public Account getFirstBankAccount(){
        QueryWrapper<Account> queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_bank",Boolean.TRUE);
        List<Account> accounts = accountMapper.selectList(queryWrapper);
        return accounts.size()==0?null:accounts.get(0);
    }


}
